<template>
    <div>
        <h3>康复理疗</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">项目名称<span style="color: red;">*</span></td>
                    <td>
                        <input type="text" v-model="info.lineName">
                    </td>
                </tr>
                <tr>
                    <td align="right">项目编码<span style="color: red;">*</span></td>
                    <td>
                        <input v-model="info.lineNum" readonly>
                    </td>
                </tr>
                <tr>
                    <td align="right">佣金<span style="color: red;">*</span></td>
                    <td>
                        <input type="text" v-model="info.linePrice">
                    </td>
                </tr>
                <tr>
                    <td align="right">服务人数<span style="color: red;">*</span></td>
                    <td>
                        <input type="number" v-model="info.lineCount">
                    </td>
                </tr>
                <tr>
                    <td align="right">服务时长<span style="color: red;">*</span></td>
                    <td>
                        <input type="number" v-model="info.lineTime">
                    </td>
                </tr>
                <tr>
                    <td align="right">项目说明<span style="color: red;">*</span></td>
                    <td>
                        <textarea v-model="info.lineHome">

                        </textarea>
                    </td>
                </tr>
                <tr>
                    <td align="right">状态</td>
                    <td>
                        <input type="radio" name="state" :value="1" v-model="info.lineState">启用
                        <input type="radio" name="state" :value="0" v-model="info.lineState">禁用
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-success" @click="AddLine">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router';
import moment from 'moment';
const router = useRouter()
const route = useRoute()
//添加参数
let info: any = reactive({
    "lineNum": moment(new Date).format('yyyyMMDD') + Math.random().toString().substring(3, 6),
    "lineName": "",
    "linePrice": '',
    "lineCount": '',
    "lineTime": '',
    "lineHome": "",
    "lineState": 1,
})
const AddLine = () => {
    if (info.lineName == "") {
        alert('项目名称不能为空')
        return
    }
    if (info.linePrice == "") {
        alert('佣金不能为空')
        return
    }
    if (info.lineCount == "") {
        alert('服务人数不能为空')
        return
    }
    if (info.lineCount < 5) {
        alert('服务人数不是整数')
        return
    }
    if (info.lineTime == "") {
        alert('服务时长不能为空')
        return
    }
    if (info.lineTime < 5) {
        alert('服务时长不是整数')
        return
    }
    if (info.lineHome == "") {
        alert('项目说明不能为空')
        return
    }
    if (info.lineState == "") {
        alert('状态必选')
        return
    }
    axios({
        url: '/api/Emp/AddLine',
        method: 'post',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert('项目名称重复')
                return
            }
            if (res.data > 0) {
                alert('添加成功')
                router.push('/showline')
            }
            else {
                alert('添加失败')
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>